﻿
using System;
using System.IO;

namespace MockingBird.Common.Infrastructure.Logging
{
    public class LoggingConfigurationProvider : ILoggingConfigurationProvider
    {
        private string loggingConfigPath;
        private bool isPathDefined;

        #region ILoggingConfigurationProvider Members

        /// <summary>
        /// The directory where the logging configuration file can be found
        /// (the file itself maybe EntLibLogging.Config or Log4net.config
        /// and the actual logger knows the name.). If this is not set, then the 
        /// system assumes it is a sibling log file
        /// </summary>
        public string LoggingConfigurationFolder
        {
            get
            {
                if (!isPathDefined)
                {
                    this.DefineDefaultPath();
                    this.isPathDefined = true;
                }

                return this.loggingConfigPath;
            }
            set
            {
                this.ValidateIncomingPath(value);
                this.loggingConfigPath = value;
                this.isPathDefined = true;
            }
        }

        private void DefineDefaultPath()
        {
            this.loggingConfigPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;

        }

        private void ValidateIncomingPath(string path)
        {
            if (!Directory.Exists(path))
            {
                throw new System.IO.DirectoryNotFoundException("Could not find the folder :" + path);
            }

        }

        #endregion
    }
}
